//
//  ViewController.m
//  PerDemo
//
//  Created by 王锋 on 2017/12/26.
//  Copyright © 2017年 王锋. All rights reserved.
//

#import "ViewController.h"

#import "BlueManager.h"

#import <CoreBluetooth/CoreBluetooth.h>

@interface ViewController ()

@property(nonatomic, strong) BlueManager *bm;

@property (weak, nonatomic) IBOutlet UILabel *label;

@property (weak, nonatomic) IBOutlet UIView *circleView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

//    self.cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{CBCentralManagerOptionShowPowerAlertKey : @YES}];
    
    //备注
    self.bm = [BlueManager standBlueManager];
    self.bm.status = BlueManagerTypeLight;
    self.bm.temper = 0;
    self.circleView.alpha = 0.1f;
    self.circleView.layer.masksToBounds = YES;
    
    
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [self.circleView addGestureRecognizer:recognizer];
    
    UISwipeGestureRecognizer *recognizer1 = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer1 setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [self.circleView addGestureRecognizer:recognizer1];
    
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.circleView.layer.cornerRadius = self.circleView.frame.size.height / 2;
}

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
    if(recognizer.direction == UISwipeGestureRecognizerDirectionDown) {
        self.circleView.alpha = 0.1;
        self.bm.status = BlueManagerTypeLight;
    }
    if(recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
        self.circleView.alpha = 0.5;
        self.bm.status = BlueManagerTypeTemperature;
    }
    [self.bm changedWithNum:0 temper:0 type:BlueManagerNumOther];
}

- (IBAction)handleAction:(UIButton *)sender {
    
    switch (sender.tag) {
        case 100://加
        {
            if (self.circleView.alpha == 0.1f) {
                self.bm.status = BlueManagerTypeLight;
            }else{
                self.bm.status = BlueManagerTypeTemperature;
            }
            [self.bm changedWithNum:16 temper:16 type:BlueManagerNumAdd];
        }
            break;
        case 101://减
        {
            if (self.circleView.alpha == 0.1f) {
                self.bm.status = BlueManagerTypeLight;
            }else{
                self.bm.status = BlueManagerTypeTemperature;
            }
            [self.bm changedWithNum:16 temper:16 type:BlueManagerNumSubtract];
        }
            break;
        case 102://白
        {
            self.bm.status = BlueManagerTypeSpecific;
            [self.bm changedWithNum:244 temper:20 type:BlueManagerNumAddSpecific];
        }
            break;
        case 103://暖
        {
            self.bm.status = BlueManagerTypeSpecific;
            [self.bm changedWithNum:80 temper:240 type:BlueManagerNumAddSpecific];
        }
            break;
        case 104://自然
        {
            self.bm.status = BlueManagerTypeSpecific;
            [self.bm changedWithNum:198 temper:214 type:BlueManagerNumAddSpecific];
        }
            break;
        case 105://氛围
        {
            self.bm.status = BlueManagerTypeSpecific;
            [self.bm changedWithNum:200 temper:200 type:BlueManagerNumAddSpecific];
        }
            break;
    }
    self.label.text = [NSString stringWithFormat:@"色温:%ldk,亮度:%ld",(self.bm.temper*5000)/255,(self.bm.num*100)/255];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
